﻿namespace WebPacker.Tests.Packs.Resources
{
	using System;
	using System.IO;
	using System.Text;
	using NUnit.Framework;
	using WebPacker.Packs.Resources;

    [TestFixture]
    public class FileResourceTest
    {
        private readonly string testFilePath = @"samples\test1.js";

		[Test]
		public void ConstructorNullTest()
		{
			Assert.Throws<ArgumentNullException>(() => new WildcardFileResource(null));
		}

		[Test]
		public void ConstructorError1Test()
		{
			Assert.Throws<ArgumentException>(() => new WildcardFileResource(@"c:\test\*??<"));
		}

        [Test]
        public void Constructor1Test()
        {
            var resource = new FileResource(testFilePath);
            Assert.AreEqual(testFilePath, resource.Name);
            Assert.AreEqual(Encoding.UTF8, resource.Encoding);
        }

        [Test]
        public void Constructor2Test()
        {
            var resource = new FileResource(testFilePath)
            {
                Encoding = Encoding.ASCII
            };
            Assert.AreEqual(testFilePath, resource.Name);
            Assert.AreEqual(Encoding.ASCII, resource.Encoding);
        }

        [Test]
        public void GetContentTest()
        {
            var resource = new FileResource(testFilePath);
            Assert.AreEqual(File.ReadAllText(testFilePath, Encoding.UTF8), resource.GetContent());
        }

        [Test]
        public void GetContentWithEncodingTest()
        {
            var resource = new FileResource(testFilePath)
            {
                Encoding = Encoding.ASCII
            };
            Assert.AreEqual(File.ReadAllText(testFilePath, Encoding.ASCII), resource.GetContent());
        }

        [Test]
        public void GetLastModifiedTime()
        {
            var resource = new FileResource(testFilePath);
            Assert.AreEqual(File.GetLastWriteTime(testFilePath), resource.GetLastModifiedTime());
        }
    }
}
